package com.ruoyi.psi.base.unit.service;


import com.ruoyi.psi.base.unit.domain.BaseUnit;
import com.ruoyi.psi.base.unit.mapper.BaseUnitMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 计量单位 业务层处理
 *
 * @author Drj 2021/6/28
 */
@Service
public class BaseUnitServiceImpl implements IBaseUnitService{
    @Autowired
    private BaseUnitMapper baseUnitMapper;

    /**
     * 根据条件查询计量单位
     *
     * @param baseUnit 计量单位信息
     * @return 计量单位集合
     */
    @Override
    public List<BaseUnit> selectBaseUnitList(BaseUnit baseUnit) {
        return baseUnitMapper.selectBaseUnitList(baseUnit);
    }

    /**
     * 根据id查询计量单位
     *
     * @param baseUnitId 计量单位编号
     * @return 计量单位集合
     */
    @Override
    public BaseUnit selectBaseUnitById(String baseUnitId) {
        return baseUnitMapper.selectBaseUnitById(baseUnitId);
    }

    /**
     * 新增计量单位
     *
     * @param baseUnit 计量单位信息
     * @return 结果
     */
    @Override
    public int insertBaseUnit(BaseUnit baseUnit) {
        if (baseUnitMapper.selectBaseUnitById(baseUnit.getBaseUnitId()) != null){//存在
            return 0;
        }
        return baseUnitMapper.insertBaseUnit(baseUnit);
    }

    /**
     * 修改计量单位数据
     *
     * @param baseUnit 计量单位信息
     * @return 结果
     */
    @Override
    public int updateBaseUnit(BaseUnit baseUnit) {
        if (baseUnitMapper.selectBaseUnitById(baseUnit.getBaseUnitId()) == null){//不存在
            return 0;
        }
        return baseUnitMapper.updateBaseUnit(baseUnit);
    }

    /**
     * 删除功能
     * 更新对应计量单位删除标志
     *
     * @param baseUnit 计量单位信息
     * @return
     */
    @Override
    public int updateBaseUnitDeleteFlag(BaseUnit baseUnit) {
        return baseUnitMapper.updateBaseUnitDeleteFlag(baseUnit);
    }
}
